package com.socodethis.spaceex;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.socodethis.spaceex.texturePackerLoader;
import com.socodethis.spaceex.math.cPoint;


public class TileHolder {
	private texturePackerLoader tFloorTiles, tStructures;
	private TileClass[][] map;
	private String defaultFloor;
	public TileHolder(){
	    //Loads the tiles into the class. Static now until i get more tiles
		tFloorTiles = new texturePackerLoader("data/tiles_level_1.txt","data/tiles_level_1.png",0);
		tStructures = new texturePackerLoader("data/structures_level_1.txt","data/structures_level_1.png",133);
		defaultFloor = "grass";
	}
	//This must be called before anything can be built
	public void buildMap(cPoint dimensions){
		map = new TileClass[(int) dimensions.getX()][(int) dimensions.getY()];
		//Build floors underneath the entire map
		for(int y = 0; y<dimensions.getY();y++){
			for(int x = 0; x<dimensions.getX();x++){
				map[x][y] = new TileClass(new SpriteProperties(defaultFloor, new Sprite(tFloorTiles.getName(defaultFloor)),0));
			}
		}
	}
	public String getDefaultFloor(){
		return defaultFloor;
	}
	public void setMapFloor(cPoint loc, String tileName){
		map[(int) loc.getX()][(int) loc.getY()].setFloor(new SpriteProperties(tileName, new Sprite(tFloorTiles.getName(tileName)),0));
	}
	public void setMapDirt(cPoint loc, String structureName){
		map[(int) loc.getX()][(int) loc.getY()].setDirt(new SpriteProperties(structureName, new Sprite(tStructures.getName(structureName)),0));
	}
	public void setMapStructure(cPoint loc, String structureName){
		map[(int) loc.getX()][(int) loc.getY()].setStructure(new SpriteProperties(structureName, new Sprite(tStructures.getName(structureName)),0));
	}
	public void setMapSwitchStructure(cPoint loc, String structureName){
		map[(int) loc.getX()][(int) loc.getY()].setSwitchStructure(new SpriteProperties(structureName, new Sprite(tStructures.getName(structureName)),0));
	}
	public SpriteProperties getFloor(cPoint loc){
		return map[(int) loc.getX()][(int) loc.getY()].getFloor();
	}
	public SpriteProperties getStructure(cPoint loc){
		return map[(int) loc.getX()][(int) loc.getY()].getStructure();
	}
	public SpriteProperties getSwitchStructure(cPoint loc){
		return map[(int) loc.getX()][(int) loc.getY()].getSwitchStructure();
	}
	public SpriteProperties getDirt(cPoint loc){
		return map[(int) loc.getX()][(int) loc.getY()].getDirt();
	}
	public void switchTile(cPoint loc){
		map[(int) loc.getX()][(int) loc.getY()].switchDaSwitch();
	}
	public boolean anyProperties(cPoint loc){
		return map[(int) loc.getX()][(int) loc.getY()].getFloor().anyProperties();
	}
	public int getPropSize(){
		return map[0][0].getFloor().getPropSize();
	}
	public TileClass getTile(cPoint loc){
		return map[(int) loc.getX()][(int) loc.getY()];
	}
	public void setPropertyFloor(cPoint loc, int index, boolean property){
		map[(int) loc.getX()][(int) loc.getY()].getFloor().setPropAtIndex(index, property);
	}
	public void setPropertyStructure(cPoint loc, int index, boolean property){
		map[(int) loc.getX()][(int) loc.getY()].getStructure().setPropAtIndex(index, property);
	}
	public void setPropertySwitchStructure(cPoint loc, int index, boolean property){
		map[(int) loc.getX()][(int) loc.getY()].getSwitchStructure().setPropAtIndex(index, property);
	}
}
